import axios from 'axios';
/**
 * 差旅计划服务数据交互统一入口
 */
'use strict';
var plan = {};

//获取差旅计划列表
plan.getTravelPlanList = function (params,success,fail) {
  /*var data = [{
    planId:'1133',
    statusTxt:'未审批',
    canCancel:true,
    title:'全球产品发布',
    fromTime:'08-11',
    toTime:'09-12'
  },{
    planId:'33444',
    statusTxt:'已审批',
    title:'拜访北京客户',
    fromTime:'09-15',
    toTime:'09-18'
  }];
  success(data);*/

  //travel/apply/list.json
  //apply/getTravelPlanListByApplyUser.json
  axios.get('travel/apply/getTravelPlanListByApplyUser.json',{
    params:params
  }).then(res => {
    var data = res.data;
    success(data);
  }).catch(fail);
};

//老版本差旅直计划
plan.getTravelPlanList2 = function (params,success,fail) {
  /*var data = [{
    planId:'1133',
    statusTxt:'未审批',
    canCancel:true,
    title:'全球产品发布',
    fromTime:'08-11',
    toTime:'09-12'
  },{
    planId:'33444',
    statusTxt:'已审批',
    title:'拜访北京客户',
    fromTime:'09-15',
    toTime:'09-18'
  }];
  success(data);*/

  //travel/apply/list.json
  //apply/getTravelPlanListByApplyUser.json
  axios.get('travel/apply/list.json',{
    params:params
  }).then(res => {
    var data = res.data;
    success(data);
  }).catch(fail);
};

//取消未审批的差旅计划
plan.cancelTravelPlan = function (planId,success,fail) {
  if(!planId) {
    success(false);
  }
  axios.get('travel/apply/revoke.json?planNo='+planId).then(res => {
    success('0' == res.data.code);
  }).catch(fail);
};

export default plan;
